<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <meta name="format-detection" content="telephone=no">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <title>注册账号</title>
    <link rel="stylesheet" href="<%=basePath%>static/css/style.css">
    <link rel="stylesheet" href="<%=basePath%>static/css/style2.css">
    <script src="<%=basePath%>static/js/jquery-3.2.1.min.js"></script>
    <script src="<%=basePath%>static/js/textjs.js"></script>
</head>
<body style="background: #e2faff">
<div class="registertop">
</div>
<div class="register">
    <form>
        <div class="registertext">
            <div class="imgdiv">
                <img src="<%=basePath%>static/picture/phone11.png">
            </div>
            <input type="text" class="phone" id="username" name="username" placeholder="手机号" maxlength="11">
        </div>
        <div class="registertext">
            <div class="imgdiv">
                <img src="../static/picture/code.png">
            </div>
            <input type="text" class="code" id="tel_check" name="tel_check" value="" placeholder="验证码">
            <a class="cxfsyz">获取验证码</a>
        </div>
        <a class="registerbtn register_btn">
            注册
        </a>
    </form>
</div>
<span class="registertip">
        注册领取5元话费，100元购物卡！
    </span>
<div class="footer">
</div>

<script type="text/javascript" src="<%=basePath%>static/js/showwapdialog.js"></script>
<script>
    $(function () {
        register.init();
    });
    var register = {
        nchash: 'e7a37603',
        share: 1,
        quickStore: 0,
        init: function () {
            register.verification();
            $('.cxfsyz').on('click', function () {
                register.getCode();
                return false;
            });
            $('.register_btn').on('click', function () {
            	register.nowSubmit();
                return false;
            });
            $('.register_txt2').on('click', function () {
                register.login();
                return false;
            });
            $('.verification').on('click', function () {
                register.reVerification();
                return false;
            });
        },
        verification: function () {
            $('.verification img').attr('src', "http://app.huitongtel.com/shop/index.php?act=seccode&op=makecode&nchash=" + register.nchash);
        },
        reVerification: function () {
            $('.verification img').attr('src', "http://app.huitongtel.com/shop/index.php?act=seccode&op=makecode&nchash=" + register.nchash + "&t=" + Math.random())
        },
        checkVerf: function () {
            register.sendCode();
            return false;
        },
        getCode: function () {
            register.checkVerf();
        },
        setRemainTime: function (curCount) {
            if (curCount == 0) {
            	$('.cxfsyz').attr("disabled", false);
                $('.cxfsyz').css("color", "rgb(253,34,28)");
                $(".cxfsyz").text("重新发送");
                register.reVerification();
            } else {
            	$('.cxfsyz').attr("disabled",true);
                $('.cxfsyz').css("color", "#7B7B7B");
                $(".cxfsyz").text(curCount + 's');
                curCount--;
                setTimeout(function () {
                    register.setRemainTime(curCount)
                }, 1000)
            }
        },
        sendCode: function () {
            var tel = $('#username').val();
            if (tel == null || $.trim(tel) == '') {
            	alert('请输入您的手机号码');
                return false;
            }
            var partten = /^(((13[0-9]{1})|(14[579]{1})|(15[^4,\D]{1})|(16[6]{1})|(18[0-9]{1})|(17[^249,\D]{1})|(19[89]{1}))+\d{8})$/;
            if (!partten.test(tel)) {
            	alert('请输入正确的手机号码');
                return false;
            }
            $.ajax({
                type: 'POST',
                url: '../login/smsInfo',
                data: {
                	Mobile: tel,
                    ParentId: "58162318-deca-4442-8e38-743b7729aa5b"
                },
                dataType: 'json',
                success: function (data) {
                    if (data.errorCode != 2000) {
                    	// 发送失败
                        alert(data.data);
                    } else {
	                    alert('验证码发送成功');
	                    var curCount = 60;
	                    register.setRemainTime(curCount);
                    }
                }
            });
        },
        // 注册
        nowSubmit: function () {
        	var username = $('#username').val();
            var tel_check = $('#tel_check').val();
            
            if (username.length == 0) {
            	alert('手机号不允许为空');
                return false;
            }
            if (tel_check.length == 0) {
            	alert('请输入短信验证码');
                return false;
            }
            var flag = false;
            // 短信验证
            $.ajax({
                type: "POST",
                dataType: "json",
                url: '../login/boofalg',
                async: false,
                data: {
                	tel_check: tel_check,
                	Mobile: username,
                	ParentID: "58162318-deca-4442-8e38-743b7729aa5b"
                },
                success: function (data) {
                    if (data == 1) {
                        alert('验证码错误请重新输入');
                        flag = true;
                    }
                }
            });
            // 验证码错误 则执行false 否则不执行这段
            if(flag)
            	return false;
            // 开始注册
            $.ajax({
                type: 'POST',
                url: '../login/registerMoney',
                data: {
                	Mobile: username,
                    ParentId: "58162318-deca-4442-8e38-743b7729aa5b",
                    Money: 100
                },
                success: function (data) {
                    if (data.errorCode != 2000) {
                        // 注册失败
                        alert(data.data);
                        location.href = "http://admin.sbdznkj.com/download/";
                    } else {
                    	// 注册成功
                    	alert("感谢您的注册，手机号码为您默认的登陆密码！");
                        location.href = "http://admin.sbdznkj.com/download/";
                    }
                },
                dataType: 'json'
            });
        },
        login: function () {
            // location.href = "../login/login";
        }
    };
</script>
</body>
</html>
